var findKthPositive = function(arr, k) {
    var result = 0, length = arr.length, max = arr[length-1], every = new Array(max+1);
    if(max-length>=k){ //在最大数组值内
        for(let i=0;i<length;i++){
            every[arr[i]] = 1;
        }
        for(let i=1;i<=every.length;i++){
            if(k<=0) return result;
            if(!every[i]){
                result = i;
                k--;
            }
        }
    } else{ //在最大数组值外
        return length+k;
    }
}; 
// ES6数组方法太费时间~
var findKthPositive2 = function(arr, k) {
    var result = 0, length = arr.length, max = arr[length-1];
    if(max-length>=k){ //在最大数组值内
        while(k>0){
            result++;
            if(arr.every(v => v !== result)){
                k--; 
            } 
        }
        return result;
    } else{ //在最大数组值外
        return length+k; // k-(max-length)+max
    }
}; 

var arr = [2,3,4,7,11], k = 5;
console.log(findKthPositive(arr,k));
console.log(findKthPositive2(arr,k));